package com.school.aftersalemanagement.callback.impl;

import android.content.Context;
import android.os.Handler;
import android.util.Log;

import com.google.gson.reflect.TypeToken;
import com.school.aftersalemanagement.callback.StringCallback;
import com.school.aftersalemanagement.entity.Bike;
import com.school.aftersalemanagement.entity.Result;
import com.zhy.http.okhttp.request.RequestCall;

import java.util.List;

/**
 * Created by winkyle on 2017/11/13.
 */

public class GetBikeCallback extends StringCallback {
    public GetBikeCallback(RequestCall requestCall, Handler handler, int messageType, Context context, boolean cycle) {
        super(requestCall, handler, messageType, context, cycle);
    }

    @Override
    public void onResponse(String response, int id) {
        Log.d(requestCall.getClass().getSimpleName()+"response", response);
        Result result = getResult(response);
        if(result.getCode()==0){
            showShort(result.getMsg());
        }else if(result.getCode()==1){
            List<Bike> bikes = gson.fromJson(result.getBody(),new TypeToken<List<Bike>>(){}.getType());
            handler.obtainMessage(messageType,bikes).sendToTarget();
        }
    }
}
